<template>
	<view class="my-container">
		 <!-- 用户未登录时，显示登录组件 -->
		<my-login :userInfo='userInfo' v-if="!token"></my-login>
		<!-- 用户登录后，显示用户信息组件 -->
		<my-userinfo :userInfo='userInfo' v-else></my-userinfo>
	</view>
</template>

<script>
	import badgeMix from '@/mixins/tabbar-badge.js'
	import { mapState } from 'vuex'
	import cloudApi from "@/common/cloundApi.js"
	export default {
		mixins: [badgeMix],
		data() {
			return {
				// 用户信息
				userInfo:null
			};
		},
		async onLoad(options){
			uni.login({
				provider:'weixin',
				success:(res) => {
					var code = res.code;
					cloudApi.call({
						name:'login',
						data:{
							code:code
						},
						success:(res) => {
							this.userInfo = res.result;
						}
					})
				}
			})
		},
		onShow(){
			uni.$on('userInfo',userInfo=>{
				this.userInfo=userInfo
			})
		},
		computed: {
		    //  从 m_user 模块中导入需要的 token 字符串
		    ...mapState('m_user', ['token']),
	  },
	}
</script>

<style lang="scss">
page,
.my-container {
  height: 100%;
}
</style>
